//应急事件管理
var toContaminantsTrack;
Ext.define('Admin.view.emergencyDispatch.EmergencyIncidentMgt', {
    extend: "Admin.common.container.BaseContainer",
    xtype: 'emergencyIncidentMgt',
    alias: 'emergencyIncidentMgt',
    requires: ['Ext.panel.Panel', 'Ext.grid.Panel', 'Ext.button.Button', 'Admin.common.form.field.DateTimeH', 'Admin.store.emergencyDispatch.EmergencyInicdnet', 'Admin.store.emergencyDispatch.WarningInfo'],
    controller: 'emergencyIncidentMgt',
    viewModel: 'emergencyIncidentMgt',
    layout: {
        type: 'vbox',
        align: 'stretch'
    },
    height: 200,
    items: [{
            xtype: 'baseGridPanel',
            title: '应急事件',
            height: 300,
            flex: 1,
            border: true,
            margin: '0 0 10 0',
            reference: 'emergencyIncidentGrid', //添加“reference”配置到表格并用lookupReference方法获取表格组件
            stripeRows: true, //斑马纹效果
            loadMask: true, //loading效果
            align: 'center',
            multiSelect: false, //允许用户在列表中同时选择多个
            listeners: {
                cellclick: 'onGridCellItemClick'
            },
            bind: {
                store: '{emergencyIncident}'
            },
            columns: [{
                    text: '事件名称',
                    dataIndex: 'evenNm',
                    flex: 1
                }, {
                    text: '事件类型',
                    dataIndex: 'evenTp',
                    flex: 1,
                    renderer: function(value) {
                        return getValue('eventp', value);
                    }
                }, {
                    text: '发布时间',
                    dataIndex: 'hapDt',
                    flex: 1
                }, {
                    text: '发生河段',
                    dataIndex: 'rcd',
                    flex: 1,
                    renderer: function(value) {
                        if (value !== 0) {
                            return getRnm(value);
                        } else {
                            return "";
                        }
                    }

                }, {
                    text: '事件描述',
                    dataIndex: 'evenD',
                    flex: 1
                }, {
                    text: '发布方式',
                    dataIndex: 'pubTp',
                    flex: 1,
                    renderer: function(value) {
                        return getValue('pubtp', value);
                    }
                },
                {
                    xtype: "actionTextcolumn",
                    text: "污染源信息",
                    width: 120,
                    sortable: false,
                    menuDisabled: true,
                    items: [{
                        showText: "追踪溯源",
                        handler: function(grid, rowIndex, colIndex) {
                            var data = grid.getStore().getAt(rowIndex);
                            config.contaminantsTrackEvenCd = data.data.evenCd;
                            window.location.hash = '#contaminantsTrack';
                        }
                    }]
                },
                {
                    text: '处置状态',
                    dataIndex: 'plS',
                    flex: 1,
                    renderer: function(value) {
                        return getValue('emergpls', value);
                    }
                }, {
                    xtype: 'actioncolumn',
                    text: '操作',
                    align: 'center',
                    width: 100,
                    sortable: false,
                    menuDisabled: true,
                    items: [{
                        iconCls: 'x-fa fa-edit',
                        tooltip: '编辑',
                        handler: 'onWarnListUpData'
                    }, {
                        iconCls: 'x-fa fa-times-circle',
                        tooltip: '删除',
                        handler: 'wanrListDel'
                    }]
                }
            ],
            tbar: [{
                    xtype: "dicComboBox",
                    dicType: 'incidentType',
                    maxWidth: 160,
                    fieldLabel: "事件类型",
                    labelWidth: 60,
                    reference: 'WARN_EVENTP',
                },
                // {
                // 	xtype: "textfield",
                // 	maxWidth: 160,
                // 	fieldLabel: "发生区域",
                // 	labelWidth: 60,
                // 	reference: 'WARN_LOC'
                // },
                {
                    xtype: "combobox",
                    maxWidth: 220,
                    fieldLabel: "发生河段",
                    labelWidth: 60,
                    reference: 'WARN_LOC',
                    displayField: 'label',
                    queryMode: 'local',
                    valueField: 'value',
                    triggerAction: 'all',
                    anyMatch: true,
                    store: Ext.create("Ext.data.Store", {
                        fields: ["label", "value"],
                        data: (function() {
                            var _result = [];
                            mriverList.forEach(function(item) {
                                if (item.river == config.RIVER) {
                                    _result.push({
                                        label: item.rnm,
                                        value: item.rcd
                                    });
                                }
                            });
                            return _result;
                        })()
                    }),
                    listeners: {
                        // added: function(combo) {
                        // var _that = this;
                        // var store = Ext.create("Ext.data.Store", {
                        //     autoLoad: true,
                        //     proxy: {
                        //         type: "ajax",
                        //         extraParams: {
                        //             river: config.RIVER
                        //         },
                        //         url: config.URL + "emergency/ddsEdEvent/list",
                        //         reader: {
                        //             type: "json",
                        //             rootProperty: "list",
                        //             fields: ["loc"]
                        //         }
                        //     }
                        // });
                        // combo.setStore(store);
                        // store.on('endupdate', function () {
                        // 	if (!combo.getValue()) {
                        // 		combo.setValue(store.getAt(0).get('conId'))
                        // 	}
                        // })
                        // }
                    }
                },
                {
                    xtype: "dicComboBox",
                    dicType: 'incidentStatus',
                    maxWidth: 160,
                    fieldLabel: "事件状态",
                    labelWidth: 60,
                    reference: 'WARN_PLS'
                }, {
                    xtype: "timesfieldh",
                    width: 250,
                    fieldLabel: "发布时间",
                    editable: true,
                    // value: config.defaultStartDate,
                    format: "Y-m-d H:i:s",
                    labelWidth: 60,
                    reference: 'WARN_STARTTM',
                    listeners: {
                        change: function() {
                            var edDt = this.nextSibling().nextSibling();
                            edDt.setMinValue(this.value);
                        }
                    }
                }, '--', {
                    xtype: "timesfieldh",
                    editable: true,
                    width: 190,
                    // value: config.defaultEndDate,
                    format: "Y-m-d H:i:s",
                    reference: 'WARN_ENDTM'
                }, '->', {
                    xtype: "button",
                    text: "查询",
                    // iconCls: "x-fa fa-search",
                    handler: 'onWarnListSearchClick'
                }, {
                    xtype: "button",
                    text: "人工填报",
                    // iconCls: "x-fa fa-file-o",
                    handler: 'onManualReportClick'
                }
            ],
            bbar: {
                xtype: "pagingtoolbar",
                autoLoad: true,
                displayInfo: true,
                displayMsg: "显示从第{0}条数据到第{1}条数据，共{2}条数据",
                emptyMsg: "没有记录"
            },
        },
        {
            xtype: 'baseGridPanel',
            title: '预警信息',
            flex: 1,
            height: 300,
            // bind: '{warginInfo}',
            reference: "meetingGrid",
            border: true,
            columns: [{
                    text: '测站编号',
                    dataIndex: 'secCd',
                    hidden: true
                },
                {
                    text: '测站名称',
                    dataIndex: 'secCd',
                    renderer: function(value) {
                        for (var a = 0; a < statList.length; a++) {
                            if (statList[a].stcd == value) {
                                return statList[a].stNm;
                            }
                        }
                    },
                    flex: 1
                },
                {
                    text: '预警指标',
                    dataIndex: 'label',
                    renderer: function(value) {
                        for (var b = 0; b < dictList.length; b++) {
                            if (dictList[b].type == "wruletype" && dictList[b].value == value) {
                                return dictList[b].label;
                            }
                        }
                    },
                    flex: 1
                }, {
                    text: '预警时间',
                    dataIndex: 'tm',
                    flex: 1
                }, {
                    text: '预警值',
                    dataIndex: 'lvalue',
                    flex: 1
                }, {
                    text: '预警级别',
                    dataIndex: 'lel',
                    flex: 1,
                    renderer: function(value) {
                        var lel = '';
                        switch (value) {
                            case "1":
                                lel = 'I';
                                break;
                            case "2":
                                lel = 'II';
                                break;
                            case "3":
                                lel = 'III';
                                break;
                            case "4":
                                lel = 'IV';
                                break;
                        }
                        return lel;
                    }
                },
                {
                    text: '状态',
                    dataIndex: 'flag',
                    flex: 1,
                    renderer: function(value) {
                        var lel = '';
                        switch (value) {
                            case "1":
                                lel = '新建';
                                break;
                            case "2":
                                lel = '确认';
                                break;
                            case "3":
                                lel = '忽略';
                                break;
                        }
                        return lel;
                    }
                },
                // {
                // 	text: '上下限标识',
                // 	dataIndex: 'updown',
                // 	renderer: function (value, record) {
                // 		if (value == 1) {
                // 			return '下限';
                // 		}else if(value == 0){
                // 			return '上限';
                // 		}else{
                // 			return '';
                // 		}
                // 	},
                // 	flex: 1,
                // },
                // {
                // 	text: '指标值',
                // 	dataIndex: 'vavule',
                // 	flex: 1
                // }, {
                // 	text: '备注',
                // 	dataIndex: 'nt',
                // 	flex: 1
                // },
                {
                    xtype: 'actioncolumn',
                    text: '操作',
                    align: 'center',
                    width: 100,
                    sortable: false,
                    menuDisabled: true,
                    items: [{
                        iconCls: 'x-fa fa-check-square-o',
                        tooltip: '确认',
                        handler: 'delmeetingGrid'
                    }, {
                        iconCls: 'x-fa fa-eye-slash',
                        tooltip: '忽略',
                        handler: 'changemeetingGrid'
                    }]
                }
            ],
            bind: {
                store: '{warginInfo}'
            },
            tbar: [
                // {
                // 	xtype: "textfield",
                // 	maxWidth: 200,
                // 	fieldLabel: "测站名称",
                // 	labelWidth: 60,
                // 	reference: 'INFOR_NAME',
                // },
                {
                    xtype: "combobox",
                    maxWidth: 220,
                    fieldLabel: "测站名称",
                    reference: "INFOR_NAME",
                    displayField: 'stNm',
                    queryMode: 'local',
                    valueField: 'stcd',
                    triggerAction: 'all',
                    anyMatch: true,
                    labelWidth: 60,
                    listeners: {
                        added: function(combo) {
                            var _that = this;
                            var store = Ext.create("Ext.data.Store", {
                                fields: ["stNm", "stcd", 'stTp'],
                                data: statList
                            });
                            store.filter({
                                property: 'river',
                                value: config.RIVER
                            });
                            combo.setStore(store);
                        }
                    }
                },
                '->', {
                    xtype: "button",
                    text: "查询",
                    iconCls: 'x-fa  fa-search',
                    handler: 'inforSearch'
                }, {
                    xtype: 'button',
                    text: '预警规则',
                    handler: 'onWarningRuleSetClick'
                }
            ],
            bbar: {
                xtype: "pagingtoolbar",
                autoLoad: true,
                displayInfo: true,
                displayMsg: "显示从第{0}条数据到第{1}条数据，共{2}条数据",
                emptyMsg: "没有记录"
            },
        }
    ]

});

Ext.define('Admin.view.emergencyDispatch.WarningRuleSet', {
    extend: 'Ext.panel.Panel',
    xtype: 'warningRuleSet',
    alias: 'widget.warningRuleSet',
    controller: 'emergencyIncidentMgt',
    items: [{
        xtype: "baseGridPanel",
        border: true,
        margin: '0 20 20 20',
        reference: 'baseGridPanel',
        listeners: {
            validateedit: 'warningRuleSetGridEdit',
            added: 'baseGridPaneladded'
        },
        columns: [{
                text: '测站编号',
                dataIndex: 'stcd',
                hidden: true
            }, {
                text: '测站名称',
                dataIndex: 'stcd',
                renderer: function(value) {
                    for (var a = 0; a < statList.length; a++) {
                        if (statList[a].stcd == value) {
                            return statList[a].stNm;
                        }
                    }
                },
                flex: 1
            }, {
                text: '预警指标',
                dataIndex: 'types',
                renderer: function(value) {
                    for (var b = 0; b < dictList.length; b++) {
                        if (dictList[b].value == value) {
                            return dictList[b].label;
                        }
                    }
                },
                flex: 1
            }, {
                text: '单位',
                align: 'center',
                dataIndex: 'dw',
                // editor: {
                // 	allowBlank: false
                // },
                flex: 1
            }, {
                text: '上下限标识',
                align: 'center',
                dataIndex: 'updown',
                // editable: false,
                renderer: function(value) {
                    if (value == 0) {
                        return '上限';
                    } else if (value == 1) {
                        return '下限';
                    }
                },
                // editor: {
                // 	xtype: "combobox",
                // 	displayField: 'label',
                // 	valueField: 'value',
                // 	listeners: {
                // 		added: function (combo) {
                // 			var _that = this;
                // 			var store = Ext.create("Ext.data.Store", {
                // 				autoLoad: true,
                // 				data: [{ label: '上限', value: 0 }, { label: '下限', value: 1 }]
                // 			});
                // 			combo.setStore(store);

                // 		}
                // 	}
                // },
                flex: 1
            }, {
                text: 'IV级预警',
                align: 'center',
                dataIndex: 'levels4',
                field: {
                    xtype: 'numberfield'
                },
                flex: 1
            }, {
                text: 'III级预警',
                align: 'center',
                dataIndex: 'levels3',
                field: {
                    xtype: 'numberfield'
                },
                flex: 1
            }, {
                text: 'II级预警',
                align: 'center',
                dataIndex: 'levels2',
                field: {
                    xtype: 'numberfield'
                },
                flex: 1
            }, {
                text: 'I级预警',
                align: 'center',
                dataIndex: 'levels1',
                field: {
                    xtype: 'numberfield'
                },
                editor: {
                    allowBlank: false
                },

                flex: 1
            },
            // {
            // 	xtype: 'actioncolumn',
            // 	text: '操作',
            // 	align: 'center',
            // 	width: 100,
            // 	sortable: false,
            // 	menuDisabled: true,
            // 	items: [
            // 	{
            // 		iconCls: 'x-fa fa-times-circle',
            // 		tooltip: '删除',
            // 		handler: 'baseGridPanelDel'
            // 	}]
            // }
        ],
        plugins: {
            ptype: "cellediting",
            clicksToEdit: 1
        },
    }],
    tbar: [{
            xtype: 'button',
            width: 60,
            text: '新增',
            margin: '0 0 0 12',
            handler: 'addwarningRuleSet'
        }
        // , {
        // 	xtype: 'button',
        // 	width: 60,
        // 	text: '保存',
        // 	margin: '0 0 0 12',
        // 	handler: 'savewarningRuleSet'
        // }
    ]
});

Ext.define('Admin.view.emergencyDispatch.ManualReport', {
    extend: 'Admin.common.form.BaseFormPanel',
    xtype: 'manualReport',
    alias: 'manualReport',
    requires: ['Admin.common.form.field.DateTimeField'],
    layout: 'form',
    items: [{
            xtype: 'textfield',
            fieldLabel: '事件名称',
            allowBlank: false,
            name: 'evenNm'
        }, {
            xtype: 'dicComboBox',
            dicType: 'incidentType',
            editable: false,
            fieldLabel: '事件类型',
            allowBlank: false,
            name: 'evenTp'
        }, {
            xtype: 'dicComboBox',
            dicType: 'dispositionType',
            editable: false,
            allowBlank: false,
            fieldLabel: '处置状态',
            name: 'plS'
        }, {
            xtype: 'timesfieldh',
            fieldLabel: '发布时间',
            format: "Y-m-d H:i:s",
            allowBlank: false,
            editable: false,
            name: 'hapDt'
        },
        {
            xtype: "combobox",
            maxWidth: 220,
            fieldLabel: "发生河段",
            labelWidth: 60,
            reference: 'WARN_LOC',
            displayField: 'label',
            queryMode: 'local',
            name: 'rcd',
            valueField: 'value',
            triggerAction: 'all',
            allowBlank: false,
            anyMatch: true,
            store: Ext.create("Ext.data.Store", {
                fields: ["label", "value"],
                data: (function() {
                    var _result = [];
                    mriverList.forEach(function(item) {
                        if (item.river == config.RIVER) {
                            _result.push({
                                label: item.rnm,
                                value: item.rcd
                            });
                        }
                    });
                    return _result;
                })()
            }),
        },
        {
            xtype: 'textarea',
            fieldLabel: '事件描述',
            name: 'evenD'
        }, {
            xtype: 'textfield',
            name: 'evenCd',
            hidden: true
        }
    ]
});

// Ext.define('Admin.view.emergencyDispatch.InforForm', {
// 	extend: 'Admin.common.form.BaseFormPanel',
// 	xtype: 'inforForm',
// 	alias: 'inforForm',
// 	layout: 'form',
// 	requires: ['Admin.common.form.field.DateTimeField'],
// 	items: [{
// 		xtype: 'textfield',
// 		fieldLabel: '事件名称',
// 		allowBlank: false,
// 		name: 'evenNm'
// 	}, {
// 		xtype: 'dicComboBox',
// 		dicType: 'incidentType',
// 		allowBlank: false,
// 		fieldLabel: '事件类型',
// 		name: 'evenTp'
// 	}, {
// 		xtype: 'timesfieldh',
// 		allowBlank: false,
// 		editable: false,
// 		fieldLabel: '发布时间',
// 		format: "Y-m-d H:i:s",
// 		name: 'hapDt'
// 	}, {
// 		xtype: 'textfield',
// 		allowBlank: false,
// 		fieldLabel: '发生区域',
// 		name: 'loc'
// 	}, {
// 		xtype: 'dicComboBox',
// 		dicType: 'dispositionType',
// 		allowBlank: false,
// 		fieldLabel: '处置状态',
// 		name: 'plS'
// 	}, {
// 		xtype: 'textarea',
// 		allowBlank: false,
// 		fieldLabel: '事件描述',
// 		name: 'evenD'
// 	}, {
// 		xtype: 'textfield',
// 		name: 'evenCd',
// 		hidden: true
// 	}]
// });